import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, ParamMap, Router, NavigationExtras } from '../../../../../node_modules/@angular/router';
import { switchMap } from '../../../../../node_modules/rxjs/operators';
import { HttpService } from '../../../core/service/http.service';

@Component({
  selector: 'app-score-class',
  templateUrl: './score-class.component.html',
  styleUrls: ['./score-class.component.scss']
})
export class ScoreClassComponent implements OnInit {
  dataSet = [];
  // 项目ID
  selectedId: number;
  // 跳转类型，0 跳转到班级成绩，1 跳转到分组演练评分
  navigateType = 0;
  constructor(
    private router: Router,
    private route: ActivatedRoute,
    private http: HttpService
  ) {

  }

  ngOnInit() {
    this.route.queryParams.subscribe(e => {
      this.selectedId = +e.id;
      this.navigateType = +e.evalue;
      return this.getClasses();
    });
  }

  getIndex(index: number) {
    index += 1;
    let reslut = index > 4 ? index % 4 : index;
    reslut = reslut === 0 ? reslut + 1 : reslut;
    return reslut;
  }

  async getClasses() {
    this.dataSet = await this.http.get<any>(`TeacherInfo/GetTeacherProjectClasses?projectId=${this.selectedId}`);
  }

  gotInfo(classid: number) {
    const navigationExtras: NavigationExtras = {
      queryParams: { id: this.selectedId, classid: classid }
    };
    if (this.navigateType === 0) {
      // 跳转到分组演练学生打分。
      this.router.navigate(['/app/scoremanager/student-group-drill-score'], navigationExtras);
    } else {
      this.router.navigate(['/app/scoremanager/StudentScoreSet'], navigationExtras);
    }
  }

}
